﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model_SSResourceManager;

namespace Presenter_SSResourceManager
{
    public class PresenterEditProfile
    {
        private readonly IViewEditProfile _viewEditProfile;
        private readonly ModelsManager _mModel;

        public PresenterEditProfile(IViewEditProfile view)
        {
            this._viewEditProfile = view;
            _mModel = ModelInstanse.Get();

        }

        public void FillFieldToEdit()
        {
            var userId = _viewEditProfile.GetUserId();
            var user = _mModel.userModel.Get(userId);
            _viewEditProfile.FillPageFields(user);
        }

        public void Update()
        {
            var userId = _viewEditProfile.GetUserId();
            var user = _mModel.userModel.Get(userId);
            var updateUser = _viewEditProfile.GatherPageFieldsInformation(user);
            _mModel.userModel.Update(user);
        }

        public void ChangePassword()
        {
            Guid userId = _viewEditProfile.GetUserId();
            int pass = _viewEditProfile.GetPassword();
            int newPass = _viewEditProfile.GetNewPassword();
            User user = _mModel.userModel.Get(userId);
            bool result = false;
            if (user.Password == pass)
            {
                user.Password = newPass;
                result = true;
            }
            _viewEditProfile.ResultOfChangePassword(result);
        }
    }
}
